import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.naming.spi.DirectoryManager;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.xml.sax.SAXException;

import sun.security.jgss.TokenTracker;

import Resources.CII_tableRender;
import Resources.CII_table_mod_render;
import Resources.CII_test_cellRend;
import Resources.Helpers;
import Resources.Rule;
import Resources.TFCCRender;
import cii_lib.CCII_COMPONENT;
import cii_lib.CCII_INTERFACE;
import cii_lib.CIIdata;
import edu.rit.util.Hex;
import java.awt.BorderLayout;

import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.apache.xerces.parsers.*; 



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**

* @author pdrabik
*/
@SuppressWarnings("serial")
public class CIIMonitor extends javax.swing.JFrame {
	private JMenuBar jMenuBar1;
	private JMenu Menu1;
	private JLabel LabelList;
	
	public AppContent RegisterOps = new AppContent("0.60");
	private Vector<JMenuItem> filesHist = new Vector<JMenuItem>();
	private JSeparator jSeparator5;
	private JMenuItem jMenuItem4; 
	private JMenuItem jMenuItem1;
	private JPopupMenu jPopupMenu1;

	 public static ImageIcon ICON_PAR = 
		    new ImageIcon("x3.png");

	private AccessModeManager accessModes;
	private AccessMode     selectedAccessMode;
	private Vector<JRadioButtonMenuItem> jRadioButtonMenuModes;
	private JTabbedPane jTabbed;
	
	private Vector<JTree> vTrees=new Vector<JTree>();
	private DefaultMutableTreeNode coppiedTreePart;
	private DefaultMutableTreeNode lastSelectedTreeNode;
	private TreePath lastSelectedTreeNodePath;
	private JTree lastSelectedTree;
	private Map<CII_Tree_Vectors,InputTaker> inputTakers
			=new HashMap<CII_Tree_Vectors,InputTaker>();
	private JPopupMenu jPopup;
	private JButton jAdvButton;
	private Vector<AdvancedView> vAdvViews;
	private JPopupMenu jPopupMenuAdv;
	private CII_Tree_Vectors lastInterface;
	private Map<CII_Tree_Vectors,XmlInterfaceData> ifDatas 
		=new HashMap<CII_Tree_Vectors,XmlInterfaceData>();
	
	private JMenu jMenu1a;
	private JSeparator jSeparator6;
	private JTextField jTextField3;
	private JLabel jLabel15;
	private JTextField jTextField2;
	private JButton jButton1;
	private JMenuItem jMenuItem10;
	private JMenuItem jMenuItem9;
	private JMenu jMenuTol;
	private JTextField jTextFieldgX;
	private JMenuItem jMenuItem8;
	private JMenuItem jMenuItem7;
	private JSeparator jSeparator4;
	private JMenu jMenuPar;
	private JMenuItem jMenuItem6;
	private JMenuItem jMenuItem5;
	private JSeparator jSeparator3;
	private JMenuItem jMenuItem3;
	private JMenuItem jMenuItem2;
	private JMenu jMenuInt;
	private JTextField jTextField1;
	private JLabel jLabel14;
	private JButton jButtonWW;
	private JTable jTableInt;
	private JScrollPane jScrollPane6;
	private JSeparator jSeparator2;
	private JLabel jLabel13;
	private JTextField jTextFieldCharInt;
	private JLabel jLabel12;
	private JLabel jLabel11;
	private JComboBox jComboBox2;
	private JButton jButtonRes;
	private JTextField jTextFieldListN;
	private JLabel jLabel10;
	private JButton jButtongoto;
	private JTextField jTextFieldgY;
	private JLabel jLabel9;
	private JTextField jTextFieldCurPos;
	private JLabel jLabel8;
	private JSeparator jSeparator1;
	private JTextField jTextFieldSize;
	private JLabel jLabel7;
	private JTable jTable4;
	private JScrollPane jScrollPane5;
	private JLabel jLabel4;
	private JLabel jLabel6;
	private JButton jButtonUnSel;
	private JScrollPane jScrollPane1;
	private JTree systemTree;
	private JLabel jLabel20;
	private JLabel jLabel19;
	private JLabel jLabel18;
	private JPanel jPanel8;
	private JPanel jPanel7;
	private JLabel jLabel17;
	private JLabel jLabel16;
	private JPanel jPanelOPS;
	private JScrollPane jScrollPane3;
	private JLabel jLabel5;
	private JComboBox jComboBox1;
	private JTextField jTextFieldChar;
	private JPanel jPanel6;
	private JPanel jPanel5;
	private JTextField jTextFieldMW;
	private JLabel jLabel3;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private JButton jButtonRef;
	private JTable jTable3;
	private JScrollPane jScrollPane4;
	private JTable jTable1;
	private JTextField jTextFieldInd;
	private JLabel jLabel2detail;
	private JTextField jTextFieldCompName;
	private JLabel jLabelDetail;
	private JButton jManag;
	private JButton jRead;
	private JPanel jPanel4;
	private JPanel jPanel1;
	private JButton jWrite;
	private ButtonGroup buttonGroup1;
	private JRadioButton jIR;
	private JRadioButton jRC;
	private JRadioButton jRW;
	private JRadioButton jWO;
	private JRadioButton jRO;
	private JRadioButton jNA;
	private JPanel jPanel2;
	private JScrollPane jScrollPane2;
	private JPanel jPanel3;
	private CII_Tree_Vectors theComponents;
	private InputTaker stad = new InputTaker();
	private boolean canWrite = false;
	private boolean canRead = true;
	
	private Rule columnView;
	private Rule rowView;
	private XLSmanager toxls = new XLSmanager();
	/**
	 * primitiveHard - true if use VME
	 */
	private boolean primitiveHard=true;
	
	public CII_Tree_Vectors lastUsed;
	public int[] param_lastCellSell = new int[2];
	/**
	 * int_lastCellSell[] :
	 * [0] - X <bR>
	 * [1] - Y <br>
	 */
	public int[] int_lastCellSell = new int[2];
	public Insets int_selection = new Insets(0,0,0,0) ;
	/**
	* Main method to display this JFrame
	*/
	public static void main(String[] args) {
		
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		CIIMonitor inst = new CIIMonitor();
		inst.setVisible(true);
	} 
	
	public CIIMonitor() {
		super("CIIMonitorek");
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setResizable(false);
			this.setFont(new java.awt.Font("Arial",0,10));
			{
				jPanel7 = new JPanel();
				BoxLayout jPanel7Layout = new BoxLayout(jPanel7, javax.swing.BoxLayout.Y_AXIS);
				jPanel7.setLayout(jPanel7Layout);
				getContentPane().add(jPanel7);
				jPanel7.setBounds(33, 21, 205, 617);
				jPanel7.setEnabled(true);
				{
					jPanel8 = new JPanel();
					BorderLayout jPanel8Layout = new BorderLayout();
					jPanel7.add(jPanel8);
					jPanel8.setPreferredSize(new java.awt.Dimension(205, 165));
					jPanel8.setLayout(jPanel8Layout);
					{
						jScrollPane1 = new JScrollPane();
						jPanel8.add(jScrollPane1, BorderLayout.CENTER);
						{
							systemTree = new JTree();
							jScrollPane1.setViewportView(getSystemTree());
							systemTree.setBounds(66, 5, 72, 64);
						}
					}
				}
				{
					
					jTabbed=new JTabbedPane();
					jPanel7.add(jTabbed);
					jTabbed.setBounds(35, 21, 205, 623);
					jTabbed.setTabPlacement(JTabbedPane.BOTTOM);
					jTabbed.setPreferredSize(new java.awt.Dimension(205, 474));

				}
			}
			{
				LabelList = new JLabel();
				getContentPane().add(LabelList);
				LabelList.setText("Components:");
				LabelList.setBounds(14, 5, 182, 14);
				LabelList.setFont(new java.awt.Font("Tahoma",1,11));
			}
			{
				jPanel3 = new JPanel();
				getContentPane().add(jPanel3);
				jPanel3.setBounds(245, 98, 294, 546);
				jPanel3.setBorder(BorderFactory.createTitledBorder(null, " Entities: ", TitledBorder.LEADING, TitledBorder.TOP));
				jPanel3.setLayout(null);
				{
					jScrollPane2 = new JScrollPane();
					jPanel3.add(jScrollPane2);
					jScrollPane2.setBounds(7, 42, 280, 252);
					{
						
						jTable1 = new JTable();
						jScrollPane2.setViewportView(jTable1);
						jTable1.setBounds(7, 42, 203, 84);
						jTable1.getTableHeader().setBounds(0, -14, 203, 14);
						//jTable1.setPreferredSize(new java.awt.Dimension(280, 252));
						jTable1.setFont(new java.awt.Font("Tahoma",0,10));
						jTable1.setEnabled(false);
						jTable1.addMouseListener(new MouseAdapter() {
							public void mouseClicked(MouseEvent evt) {
								try{
								int adder = ParamsCountIntCount(stad.getCompTokens(new Integer(lastUsed.get(0))))[0];
								int ind = evt.getPoint().y/jTable1.getRowHeight(); // ! table row high
								if (ind>= adder-1) ind = adder-1;
								CII_Tree_Vectors tmp = new CII_Tree_Vectors();
									//jTable1.getR
									tmp = stad.getCompTokens(new Integer(lastUsed.get(0))).get(ind);
									String link = new String(lastUsed.getLink());
									lastUsed=tmp;
									lastUsed.setLink(link);
									jPanel5.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), 
											" Parameters : "+tmp.Clear(1), TitledBorder.LEADING, TitledBorder.TOP));
									jTable1.changeSelection(evt.getPoint().y/jTable1.getRowHeight(), 0, false, false);
									EngageData(tmp);
								} catch (Exception e) {
									//mouse out of table
								}
							}
						});
					}
				}
				{
					jScrollPane4 = new JScrollPane();
					jPanel3.add(jScrollPane4);
					jScrollPane4.setBounds(7, 322, 280, 210);
					{
						TableModel jTable3Model = new DefaultTableModel();
						jTable3 = new JTable();
						jScrollPane4.setViewportView(jTable3);
						jTable3.setModel(jTable3Model);
						jTable3.setEnabled(false);
						//jTable3.setPreferredSize(new java.awt.Dimension(259, 231));
						jTable3.addMouseListener(new MouseAdapter() {
							public void mouseClicked(MouseEvent evt) {
								try{
								int adder = ParamsCountIntCount(stad.getCompTokens(new Integer(lastUsed.get(0))))[0];
					
								int ind = adder+ evt.getPoint().y/jTable3.getRowHeight(); // ! table row high
								CII_Tree_Vectors tmp = new CII_Tree_Vectors();
									tmp = stad.getCompTokens(new Integer(lastUsed.get(0))).get(ind);
									String link = new String(lastUsed.getLink());
									lastUsed=tmp;
									lastUsed.setLink(link);
									jPanel6.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED),
											" Interfaces : "+tmp.Clear(1), TitledBorder.LEADING, TitledBorder.TOP));
									jTable3.changeSelection(evt.getPoint().y/jTable3.getRowHeight(), 0, false, false);
									EngageData2(tmp);
									jAdvButton.setEnabled(true);
								} catch (Exception e) {
									//mouse out of table
								}
								
							}
						});
					}
				}
				{
					jLabel1 = new JLabel();
					jPanel3.add(jLabel1);
					jLabel1.setText("Parameters");
					jLabel1.setBounds(112, 14, 77, 28);
				}
				{
					jLabel2 = new JLabel();
					jPanel3.add(jLabel2);
					jLabel2.setText("Interfaces");
					jLabel2.setBounds(112, 294, 63, 28);
				}
			}
			{
				jPanel2 = new JPanel();
				String panelName = new String(" Access ");
				if (primitiveHard) panelName= panelName+" VME";
					else panelName=panelName+" USB";
				getContentPane().add(jPanel2);
				jPanel2.setBounds(602, 560, 217, 84);
				jPanel2.setBorder(BorderFactory.createTitledBorder(null, panelName, TitledBorder.LEADING, TitledBorder.TOP));
				jPanel2.setLayout(null);
				{
					jNA = new JRadioButton();
					jPanel2.add(jNA);
					jNA.setText("NA");
					jNA.setBounds(14, 14, 42, 21);
				}
				{
					jRO = new JRadioButton();
					jPanel2.add(jRO);
					jRO.setText("RO");
					jRO.setBounds(56, 14, 42, 21);
				}
				{
					jWO = new JRadioButton();
					jPanel2.add(jWO);
					jWO.setText("WO");
					jWO.setBounds(105, 14, 49, 21);
				}
				{
					jRW = new JRadioButton();
					jPanel2.add(jRW);
					jRW.setText("RW");
					jRW.setBounds(105, 35, 49, 21);
				}
				{
					jRC = new JRadioButton();
					jPanel2.add(jRC);
					jRC.setText("RC");
					jRC.setBounds(154, 14, 42, 21);
				}
				{
					jIR = new JRadioButton();
					jPanel2.add(jIR);
					jIR.setText("IR");
					jIR.setBounds(56, 35, 42, 21);
				}
				{
					buttonGroup1 = new ButtonGroup();
					buttonGroup1.add(jNA);
					buttonGroup1.add(jRO);
					buttonGroup1.add(jWO);
					buttonGroup1.add(jRW);
					buttonGroup1.add(jRC);
					buttonGroup1.add(jIR);
					
					jNA.setEnabled(false);
					jRO.setEnabled(false);
					jWO.setEnabled(false);
					jRW.setEnabled(false);
					jRC.setEnabled(false);
					jIR.setEnabled(false);
					
					{
						jRead = new JButton();
						jPanel2.add(jRead);
						jRead.setText("Read");
						jRead.setBounds(7, 63, 63, 21);
						jRead.setFont(new java.awt.Font("Tahoma",0,11));
						jRead.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								File tt = new File(new File("").getAbsolutePath()+"\\"+lastUsed.getLink()+"\\"+lastUsed.Clear(1)+"\\data.dcii");
								if (tt.exists()) tt.delete();
								//Read_fake();
								Read_one();
								//TODO add your code for jButtonRR.actionPerformed
							}
						});
					}
					{
						jWrite = new JButton();
						jPanel2.add(jWrite);
						jWrite.setText("Write");
						jWrite.setBounds(147, 63, 63, 21);
						if (!canWrite) jWrite.setEnabled(false); else jWrite.setEnabled(true);
						jWrite.setFont(new java.awt.Font("Tahoma",0,11));
						jWrite.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								//Write_one(new Long(jTextFieldOperTest.getText()));
								long tm = new Long(""+jTableInt.getValueAt(jTableInt.getSelectedRow(),
										jTableInt.getSelectedColumn()).toString().trim());
								System.out.println(tm);
								//write_fake(tm);
								Write_one(tm);
							}
						});

					}
					{
						jManag = new JButton();
						jPanel2.add(jManag);
						jManag.setText("WriteRead");
						jManag.setBounds(70, 63, 77, 21);
						jManag.setMargin(new Insets(1,2,2,2));
						jManag.setFont(new java.awt.Font("Tahoma",0,11));
						if (!canWrite || !canRead) jManag.setEnabled(false); else jManag.setEnabled(true);
						jManag.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								IOBits iofile = new IOBits();
								iofile.initGUI();
								//TODO add your code for jManag.actionPerformed
							}
						});
					}
				}
			}
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1);
				jPanel1.setBounds(245, 14, 294, 77);
				jPanel1.setBorder(BorderFactory.createTitledBorder(" Component details: "));
				jPanel1.setLayout(null);
				{
					jLabelDetail = new JLabel();
					jPanel1.add(jLabelDetail);
					jLabelDetail.setText("Index of");
					jLabelDetail.setBounds(7, 21, 49, 21);
					jLabelDetail.setFont(new java.awt.Font("Tahoma",0,11));
				}
				{
					jTextFieldCompName = new JTextField();
					jPanel1.add(jTextFieldCompName);
					jTextFieldCompName.setBounds(49, 21, 119, 21);
					jTextFieldCompName.setEnabled(false);
					jTextFieldCompName.setDisabledTextColor(new java.awt.Color(64,0,128));
				}
				{
					jLabel2detail = new JLabel();
					jPanel1.add(jLabel2detail);
					jLabel2detail.setText(":");
					jLabel2detail.setBounds(168, 21, 7, 21);
					jLabel2detail.setFont(new java.awt.Font("Tahoma",0,12));
				}
				{
					jTextFieldInd = new JTextField();
					jPanel1.add(jTextFieldInd);
					jTextFieldInd.setBounds(175, 21, 35, 21);
					jTextFieldInd.setEnabled(false);
					jTextFieldInd.setDisabledTextColor(new java.awt.Color(64,0,128));
					jTextFieldInd.setFont(new java.awt.Font("Tahoma",1,11));
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("Main width:");
					jLabel3.setBounds(7, 49, 70, 21);
					jLabel3.setFont(new java.awt.Font("Tahoma",0,11));
				}
				{
					jTextFieldMW = new JTextField();
					jPanel1.add(jTextFieldMW);
					jTextFieldMW.setText("0");
					jTextFieldMW.setBounds(70, 49, 35, 21);
					jTextFieldMW.setEditable(false);
					jTextFieldMW.setFont(new java.awt.Font("Tahoma",1,11));
				}
			}
			{
				jPanel4 = new JPanel();
				BoxLayout jPanel4Layout = new BoxLayout(
					jPanel4,
					javax.swing.BoxLayout.Y_AXIS);
				getContentPane().add(jPanel4);
				jPanel4.setBounds(553, 14, 315, 539);
				jPanel4.setLayout(jPanel4Layout);
				jPanel4.setBorder(BorderFactory.createTitledBorder(" OPS "));
				{
					jPanel5 = new JPanel();
					jPanel4.add(jPanel5);
					jPanel5.setLayout(null);
					jPanel5.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), " Parameters ", TitledBorder.LEADING, TitledBorder.TOP));
					{
						
						jLabel4 = new JLabel();
						jPanel5.add(jLabel4);
						jLabel4.setText("Character: ");
						jLabel4.setBounds(7, 21, 63, 21);
						jLabel4.setFont(new java.awt.Font("Tahoma",0,11));
					}
					{
						jTextFieldChar = new JTextField();
						jPanel5.add(jTextFieldChar);
						jTextFieldChar.setBounds(63, 21, 91, 21);
						jTextFieldChar.setEditable(false);
						jTextFieldChar.setFont(new java.awt.Font("Tahoma",1,11));
						jTextFieldChar.setDisabledTextColor(new java.awt.Color(64,0,64));
					}
					{
						ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
							new String[] { "ASCII", "Int","U2","Hex" });
						jComboBox1 = new JComboBox();
						jPanel5.add(jComboBox1);
						jComboBox1.setModel(jComboBox1Model);
						jComboBox1.setBounds(231, 21, 63, 21);
					}
					{
						jLabel5 = new JLabel();
						jPanel5.add(jLabel5);
						jLabel5.setText("displayed as:");
						jLabel5.setBounds(161, 21, 70, 21);
						jLabel5.setFont(new java.awt.Font("Tahoma",0,11));
					}
					{
						jLabel6 = new JLabel();
						jPanel5.add(jLabel6);
						jLabel6.setText("Data set:");
						jLabel6.setBounds(7, 63, 63, 21);
					}
					{
						jScrollPane5 = new JScrollPane();
						jPanel5.add(jScrollPane5);
						jScrollPane5.setBounds(7, 84, 294, 147);
						{
							//TODO rowHEADER
							columnView = new Rule(Rule.HORIZONTAL, false);
							rowView = new Rule(Rule.VERTICAL, false);
						    
							jTable4 = new JTable();
							jTable4.getTableHeader().setVisible(true);
							jTable4.getTableHeader().setBounds(0, 291, 0, 0);
							jTable4.getTableHeader().setReorderingAllowed(false);
							jTable4.getTableHeader().setResizingAllowed(false);
							jTable4.getTableHeader().addMouseListener(new MouseAdapter(){
								public void mouseClicked(MouseEvent evt) {
									System.out.println(evt.getX()/(jTable4.getWidth()/jTable4.getColumnCount()));
								}
								
							});
							jTable4.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
							jTable4.setColumnSelectionAllowed(true);
							jTable4.setRowSelectionAllowed(true);
							jScrollPane5.setViewportView(jTable4);
							jScrollPane5.setColumnHeaderView(columnView);
							
							jTable4.addMouseListener(new MouseAdapter() {
								public void mouseClicked(MouseEvent evt) {
									jTextFieldCurPos.setText(""+evt.getX()/(jTable4.getWidth()/jTable4.getColumnCount())+
											" ; "+evt.getPoint().y/jTable4.getRowHeight());
									param_lastCellSell[0] = evt.getX()/(jTable4.getWidth()/jTable4.getColumnCount());
									param_lastCellSell[1] = evt.getPoint().y/jTable4.getRowHeight();
									jTable4.changeSelection(evt.getPoint().y/jTable4.getRowHeight()
											, evt.getX()/(jTable4.getWidth()/jTable4.getColumnCount()), false, false);
									//jTable4.removeColumnSelectionInterval(0, 1);
									
								}
								
								public void mouseReleased(MouseEvent evt) {
									
									int il =jTable4.getSelectedColumnCount()*
											jTable4.getSelectedRowCount();
									
									System.out.println(il);
								}
							});
							//jTable4.setModel(jTable4Model);
						}
					}
					{
						jLabel7 = new JLabel();
						jPanel5.add(jLabel7);
						jLabel7.setText("Width: ");
						jLabel7.setBounds(7, 42, 63, 21);
						jLabel7.setFont(new java.awt.Font("Tahoma",0,11));
					}
					{
						jTextFieldSize = new JTextField();
						jPanel5.add(jTextFieldSize);
						jTextFieldSize.setText("0");
						jTextFieldSize.setBounds(63, 42, 91, 21);
						jTextFieldSize.setEditable(false);
						jTextFieldSize.setFont(new java.awt.Font("Tahoma",1,11));
					}
					{
						jLabel8 = new JLabel();
						jPanel5.add(jLabel8);
						jLabel8.setText("Current:");
						jLabel8.setBounds(7, 231, 49, 21);
						jLabel8.setFont(new java.awt.Font("Tahoma",0,11));
					}
					{
						jTextFieldCurPos = new JTextField();
						jPanel5.add(jTextFieldCurPos);
						jTextFieldCurPos.setText("0 ; 0");
						jTextFieldCurPos.setBounds(56, 231, 35, 21);
						jTextFieldCurPos.setEditable(false);
					}
					{
						jLabel9 = new JLabel();
						jPanel5.add(jLabel9);
						jLabel9.setText(";");
						jLabel9.setBounds(266, 231, 7, 21);
						jLabel9.setFont(new java.awt.Font("Tahoma",0,11));
					}
					{
						jTextFieldgX = new JTextField();
						jPanel5.add(jTextFieldgX);
						jTextFieldgX.setText("0");
						jTextFieldgX.setBounds(245, 231, 21, 21);
					}
					{
						jTextFieldgY = new JTextField();
						jPanel5.add(jTextFieldgY);
						jTextFieldgY.setText("0");
						jTextFieldgY.setBounds(273, 231, 21, 21);
					}
					{
						jButtongoto = new JButton();
						jPanel5.add(jButtongoto);
						jButtongoto.setText("Go to: ");
						jButtongoto.setBounds(189, 231, 56, 21);
						jButtongoto.setFont(new java.awt.Font("Tahoma",0,11));
						jButtongoto.setMargin(new Insets(1,2,2,2));
						jButtongoto.setVerticalTextPosition(SwingConstants.TOP);
						jButtongoto.setVerticalAlignment(SwingConstants.TOP);
						jButtongoto.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								int x = new Integer(jTextFieldgX.getText());
								int y = new Integer(jTextFieldgY.getText());
								param_lastCellSell[0] = x;
								param_lastCellSell[1] = y;
								jTable4.changeSelection(y, x, false, false);
								jTextFieldCurPos.setText(""+x+" ; "+y);
							}
						});
					}
					{
						jLabel10 = new JLabel();
						jPanel5.add(jLabel10);
						jLabel10.setText("List name:");
						jLabel10.setBounds(126, 63, 63, 21);
						jLabel10.setVisible(false);
					}
					{
						jTextFieldListN = new JTextField();
						jPanel5.add(jTextFieldListN);
						jTextFieldListN.setBounds(189, 63, 112, 21);
						jTextFieldListN.setEditable(false);
						jTextFieldListN.setVisible(false);
						jTextFieldListN.setFont(new java.awt.Font("Tahoma",0,11));
					}
					{
						jSeparator1 = new JSeparator();
						jPanel5.add(jSeparator1);
						jSeparator1.setBounds(7, 63, 294, 7);
					}
				}
				{
					jPanel6 = new JPanel();
					jPanel4.add(jPanel6);
					jPanel6.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), " Interfaces ", TitledBorder.LEADING, TitledBorder.TOP));
					jPanel6.setLayout(null);
					{
						ComboBoxModel jComboBox2Model = new DefaultComboBoxModel(
							new String[] { "U2", "Hex","Int","ASCII" });
						jComboBox2 = new JComboBox();
						jPanel6.add(jComboBox2);
						jComboBox2.setModel(jComboBox2Model);
						jComboBox2.setBounds(231, 21, 63, 21);
						jComboBox2.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								//TODO to przez inny watek / niedobrze zaimplementowane
								if (jComboBox2.getSelectedIndex()==0) {
									for (int i=0;i<jTableInt.getColumnCount();i++) {
										for (int j=0;j<jTableInt.getRowCount();j++) {
											Object qq = jTableInt.getValueAt(j, i);
											String tmp = new String(""+qq);
											try {
												jTableInt.setValueAt(Long.toBinaryString(Hex.toLong(tmp)), j, i);
											} catch (IllegalArgumentException e ) {
												System.out
														.println(e.getMessage());
											}
										}
										
									}
								}
								if (jComboBox2.getSelectedIndex()==1) {
									for (int i=0;i<jTableInt.getColumnCount();i++) {
										for (int j=0;j<jTableInt.getRowCount();j++) {
											Object qq = jTableInt.getValueAt(j, i);
											long ltmp = stad.LongFromU2(""+qq);
											jTableInt.setValueAt(Long.toHexString(ltmp), j, i);
										}
										
									}
								}
								if (jComboBox2.getSelectedIndex()==2) {
									for (int i=0;i<jTableInt.getColumnCount();i++) {
										for (int j=0;j<jTableInt.getRowCount();j++) {
											Object qq = jTableInt.getValueAt(j, i);
											long ltmp = stad.LongFromU2(""+qq);
											jTableInt.setValueAt((ltmp), j, i);
										}
										
									}
								}
								if (jComboBox2.getSelectedIndex()==3) {
									for (int i=0;i<jTableInt.getColumnCount();i++) {
										for (int j=0;j<jTableInt.getRowCount();j++) {
											
											jTableInt.setValueAt("?", j, i);
										}
										
									}
								}
								//TODO add your code for jComboBox2.actionPerformed
							}
						});
					}
					{
						jLabel11 = new JLabel();
						jPanel6.add(jLabel11);
						jLabel11.setText("displayed as:");
						jLabel11.setFont(new java.awt.Font("Tahoma",0,11));
						jLabel11.setBounds(161, 21, 70, 21);
					}
					{
						jLabel12 = new JLabel();
						jPanel6.add(jLabel12);
						jLabel12.setText("Character: ");
						jLabel12.setFont(new java.awt.Font("Tahoma",0,11));
						jLabel12.setBounds(7, 21, 63, 21);
					}
					{
						jTextFieldCharInt = new JTextField();
						jPanel6.add(jTextFieldCharInt);
						jTextFieldCharInt.setBounds(63, 21, 91, 21);
						jTextFieldCharInt.setEditable(false);
						jTextFieldCharInt.setFont(new java.awt.Font("Tahoma",1,11));
					}
					{
						jLabel13 = new JLabel();
						jPanel6.add(jLabel13);
						jLabel13.setText("Data set:");
						jLabel13.setBounds(7, 49, 63, 21);
					}
					{
						jSeparator2 = new JSeparator();
						jPanel6.add(jSeparator2);
						jSeparator2.setBounds(7, 49, 294, 7);
					}
					{
						jScrollPane6 = new JScrollPane();
						jPanel6.add(jScrollPane6);
						jScrollPane6.setBounds(7, 70, 294, 161);
						{
							columnView = new Rule(Rule.HORIZONTAL, false);
							rowView = new Rule(Rule.VERTICAL, false);
						    
							jTableInt = new JTable();
							jTableInt.setDefaultRenderer(Component.class,
									new TFCCRender(jTableInt.getDefaultRenderer(Component.class)));
							jTableInt.getTableHeader().setVisible(true);
							jTableInt.getTableHeader().setBounds(0, 291, 0, 0);
							jTableInt.getTableHeader().setReorderingAllowed(false);
							jTableInt.getTableHeader().setResizingAllowed(true);
							jTableInt.getTableHeader().addMouseListener(new MouseAdapter(){
								public void mouseClicked(MouseEvent evt) {
									System.out.println(evt.getX()/(jTableInt.getWidth()/jTableInt.getColumnCount()));
								}
								
							});
							jTableInt.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
							jTableInt.setColumnSelectionAllowed(true);
							jTableInt.setAutoResizeMode(0);
							jTableInt.setRowSelectionAllowed(true);
							jScrollPane6.setViewportView(jTableInt);
							jScrollPane6.setColumnHeaderView(columnView);
								
								jTableInt.setColumnSelectionAllowed(true);
								jTableInt.setRowSelectionAllowed(true);
								{
									jPopupMenu1 = new JPopupMenu();
									setComponentPopupMenu(
										jTableInt,
										jPopupMenu1);
									jPopupMenu1.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
									{
										jMenuItem2 = new JMenuItem();
										jPopupMenu1.add(jMenuItem2);
										if (!canRead) jMenuItem2.setEnabled(false);
										else jMenuItem2.setEnabled(true);
										jMenuItem2.setText("Read Selection");
										jMenuItem2
											.addActionListener(new ActionListener() {
												public void actionPerformed(
													ActionEvent evt) {
													Read_many(int_selection);
												}
											});
									}
									{
										jMenuItem3 = new JMenuItem();
										jPopupMenu1.add(jMenuItem3);
										if (!canRead) jMenuItem3.setEnabled(false);
										else jMenuItem3.setEnabled(true);
										jMenuItem3.setText("Read Everything");
									}
									{
										jSeparator3 = new JSeparator();
										jPopupMenu1.add(jSeparator3);
									}
									{
										jMenuItem5 = new JMenuItem();
										jPopupMenu1.add(jMenuItem5);
										jMenuItem5.setText("Write Selection");
										if (!canWrite) jMenuItem5.setEnabled(false);
										else jMenuItem5.setEnabled(true);
										jMenuItem5
											.addActionListener(new ActionListener() {
											public void actionPerformed(
												ActionEvent evt) {
												Write_many(int_selection);
											}
											});

									}
									{
										jMenuItem6 = new JMenuItem();
										jPopupMenu1.add(jMenuItem6);
										jMenuItem6.setText("Write Everything");
										if (!canWrite) jMenuItem6.setEnabled(false);
										else jMenuItem6.setEnabled(true);
									}
									{
										jSeparator4 = new JSeparator();
										jPopupMenu1.add(jSeparator4);
									}
									{
										jMenuItem10 = new JMenuItem();
										jPopupMenu1.add(jMenuItem10);
										jMenuItem10.setText("Select all");
										jMenuItem10
											.addActionListener(new ActionListener() {
											public void actionPerformed(
												ActionEvent evt) {
												jTableInt.selectAll();
											}
											});
									}
									{
										jMenuItem7 = new JMenuItem();
										jPopupMenu1.add(jMenuItem7);
										jMenuItem7.setText("Clear Selection");
										jMenuItem7
											.addActionListener(new ActionListener() {
											public void actionPerformed(
												ActionEvent evt) {
												jTableInt.clearSelection();
											}
											});
									}
									{
										jMenuItem1 = new JMenuItem();
										jPopupMenu1.add(jMenuItem1);
										jMenuItem1.setText("Mark");
										jMenuItem1.setEnabled(false);
									}
									{
										jMenuItem4 = new JMenuItem();
										jPopupMenu1.add(jMenuItem4);
										jMenuItem4.setText("Unmark");
										jMenuItem4.setEnabled(false);
									}
								}
								jTableInt.addMouseListener(new MouseAdapter() {
									public void mouseReleased(MouseEvent evt) {
										//TODO add your code for jTableInt.mouseClicked
										int il = jTableInt.getSelectedColumnCount()
											* jTableInt.getSelectedRowCount();
										if (il>1) int_selection = new Insets(jTableInt.getSelectedRows()[0],
												jTableInt.getSelectedColumns()[0],
												jTableInt.getSelectedRows()[jTableInt.getSelectedRowCount()-1],
												jTableInt.getSelectedColumns()[jTableInt.getSelectedColumnCount()-1]);
										
										
									}
									public void mouseClicked(MouseEvent evt) {
										jTextField1.setText(""
											+ evt.getX()
											/ (jTableInt.getWidth() / jTableInt
												.getColumnCount())
											+ " ; "
											+ evt.getPoint().y
											/ jTableInt.getRowHeight());
										
										int_lastCellSell[0] = evt.getX()
											/ (jTableInt.getWidth() / jTableInt
												.getColumnCount());
										int_lastCellSell[1] = evt.getPoint().y
											/ jTableInt.getRowHeight();
										
										int addr = stad.countAddr(lastUsed,int_lastCellSell[0],int_lastCellSell[1]);
										//System.out.println(addr/8);
										//TODO F
										jTableInt.changeSelection(evt.getPoint().y
											/ jTableInt.getRowHeight(), evt.getX()
											/ (jTableInt.getWidth() / jTableInt
												.getColumnCount()), false, false);
									}
								});
						}
					}
					{
						jButtonWW = new JButton();
						jPanel6.add(jButtonWW);
						jButtonWW.setText("Modify");
						jButtonWW.setBounds(205, 231, 70, 21);
						jButtonWW.setFont(new java.awt.Font("Tahoma",0,11));
						jButtonWW.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								//int to = new Integer(jTextFieldOperTest.getText());
								
								useModify();
								
							}
						});
					} 
					{
						jLabel14 = new JLabel();
						jPanel6.add(jLabel14);
						jLabel14.setText("Current:");
						jLabel14.setFont(new java.awt.Font("Tahoma",0,11));
						jLabel14.setBounds(5, 231, 49, 21);
					}
					{
						jTextField1 = new JTextField();
						jPanel6.add(jTextField1);
						jTextField1.setText("0 ; 0");
						jTextField1.setEditable(false);
						jTextField1.setBounds(56, 231, 35, 21);
					}
					{
						jButton1 = new JButton();
						jPanel6.add(jButton1);
						jButton1.setText("Go to: ");
						jButton1.setVerticalAlignment(SwingConstants.TOP);
						jButton1.setVerticalTextPosition(SwingConstants.TOP);
						jButton1.setMargin(new Insets(1,2,2,2));
						jButton1.setFont(new java.awt.Font("Tahoma",0,11));
						jButton1.setBounds(98, 231, 55, 21);
						jButton1.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								int x = new Integer(jTextField2.getText());
								int y = new Integer(jTextField3.getText());
								int_lastCellSell[0] = x;
								int_lastCellSell[1] = y;
								jTableInt.changeSelection(y, x, false, false);
								jTextField1.setText("" + x + " ; " + y);
							}
						});
					}
					{
						jTextField2 = new JTextField();
						jPanel6.add(jTextField2);
						jTextField2.setText("0");
						jTextField2.setBounds(154, 231, 21, 21);
					}
					{
						jLabel15 = new JLabel();
						jPanel6.add(jLabel15);
						jLabel15.setText(";");
						jLabel15.setFont(new java.awt.Font("Tahoma",0,11));
						jLabel15.setBounds(175, 231, 7, 21);
					}
					{
						jTextField3 = new JTextField();
						jPanel6.add(jTextField3);
						jTextField3.setText("0");
						jTextField3.setBounds(182, 231, 21, 21);
					}
					{
						jPopupMenuAdv=new JPopupMenu();
						final JMenuItem mnu=new JMenuItem("Open in new Window");
						final JMenu mnu1=new JMenu("Add to View");
						jPopupMenuAdv.add(mnu);
						jPopupMenuAdv.add(mnu1);
						
						mnu.addActionListener(new ActionListener()
						{
							public void actionPerformed(ActionEvent evt) {
								addAdvancedView();
								updateViewList(mnu1);
							}
						});
									
						vAdvViews=new Vector<AdvancedView>();
						jAdvButton=new JButton("A");
						jAdvButton.setEnabled(false);
						jPanel6.add(jAdvButton);
						jAdvButton.setFont(new java.awt.Font("Tahoma",0,11));
						jAdvButton.setBounds(275, 231, 25, 21);
						jAdvButton.setVisible(true);
						jAdvButton.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {

								if(vAdvViews.size()==0)
								{
									addAdvancedView();
									updateViewList(mnu1);
								} else 
								{
									jPopupMenuAdv.show(jAdvButton, 0, 0);
								}	
									
							}
						});
					}
				}
			}
			{
				jButtonRef = new JButton();
				getContentPane().add(jButtonRef);
				jButtonRef.setText("Refresh");
				jButtonRef.setBounds(154, 644, 77, 21);
				jButtonRef.setFont(new java.awt.Font("Tahoma",0,11));
				jButtonRef.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
//						TableColumn tc = new TableColumn(0), tc2 = new TableColumn(1);
//						tc.setHeaderValue("1");
//						tc2.setHeaderValue("2");
//						jTable3.addColumn(tc);
//						jTable3.addColumn(tc2);
						
						//TODO add your code for jButtonRef.actionPerformed
					}
				});
			}
			{
				jButtonUnSel = new JButton();
				getContentPane().add(jButtonUnSel);
				jButtonUnSel.setText("Refresh");
				jButtonUnSel.setBounds(462, 644, 77, 21);
				jButtonUnSel.setFont(new java.awt.Font("Tahoma",0,11));
			}
			{
				jButtonRes = new JButton();
				getContentPane().add(jButtonRes);
				jButtonRes.setText("Reset");
				jButtonRes.setBounds(14, 644, 70, 21);
				jButtonRes.setFont(new java.awt.Font("Tahoma",0,11));
				jButtonRes.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						Reset();
						jTable1.clearSelection();
						jTable3.clearSelection();
						Iterator<JTree> it=vTrees.iterator();
						while(it.hasNext())
							it.next().clearSelection();						 
					}
				});
			}
			{
				jScrollPane3 = new JScrollPane();
				jScrollPane3.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
				jScrollPane3.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
				getContentPane().add(jScrollPane3);
				jScrollPane3.setBounds(0, 23, 35, 616);
				{
					jPanelOPS = new JPanel();
					jPanelOPS.setLayout(null);
					jScrollPane3.setViewportView(jPanelOPS);
					{
						jLabel16 = new JLabel();
						jPanelOPS.add(jLabel16);
						jLabel16.setText("item1");
						jLabel16.setIcon(new ImageIcon("pic\\open.png"));
						jLabel16.setToolTipText("Open extended action panel");
						jLabel16.setBounds(0, 0, 32, 30);
						jLabel16.addMouseListener(new MouseAdapter() {
							public void mouseReleased(MouseEvent evt) {
								jLabel16.setBorder(null);
							}
							public void mousePressed(MouseEvent evt) {
//								jLabel16.setBorder(new EtchedBorder(new Color(
//									0,
//									0,
//									255), new Color(120, 120, 222)));
								jLabel16.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
							}
							public void mouseClicked(MouseEvent evt) {
								File plik=new File("");
								JFileChooser wybor = new JFileChooser();
								
								wybor.setCurrentDirectory(new File("./"));
								wybor.setDialogTitle("Select class implementation");
								wybor.setFileFilter(new FileFilter() {
									@Override
									public String getDescription() {
										return "class";
									}
								
									@Override
									public boolean accept(File f) {
										if (f.isDirectory()) {
											return true;
										    }
										if (f.getName().substring(f.getName().indexOf(".")+1).equals("class"))
											return true;
										else
											return false;
									}
								
								});
								int wynik = wybor.showOpenDialog(wybor);
								if (wynik == JFileChooser.CANCEL_OPTION)
									return;
								try {
									plik = wybor.getSelectedFile();
									} catch (Exception e) {
									System.out
										.println("Adonath: Error reading file");
								}
									java.lang.ClassLoader cl;
//									System.out.println(plik.getName());
									File tmp = new File(plik.getParent());
									try {
										URL url = tmp.toURI().toURL();
										URL[] urls = new URL[]{url};
										cl = new URLClassLoader(urls);
										Class<?> cls = cl.loadClass(plik.getName().replace(".class", ""));
										cls.newInstance();
//										System.out.println(comp.HardwareRead(111));
										
									} catch (Exception e) {
										System.out.println("cl "+e);
										// TODO: handle exception
									}
								//TODO add your code for jLabel16.mouseClicked
							}
						});
					}
					{

						jLabel17 = new JLabel();
						jPanelOPS.add(jLabel17);
						jLabel17.setText("item2");
						jLabel17.setIcon(new ImageIcon("pic\\open.png"));
						jLabel17.setToolTipText("Do something else");
						jLabel17.setBounds(0, 35, 32, 30);
						jLabel17.addMouseListener(new MouseAdapter() {
							public void mouseReleased(MouseEvent evt) {
								jLabel17.setBorder(null);
							}
							public void mousePressed(MouseEvent evt) {
//								jLabel17.setBorder(new EtchedBorder(new Color(
//									0,
//									0,
//									255), new Color(120, 120, 222)));
								jLabel17.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
							}
							public void mouseClicked(MouseEvent evt) {
								File plik=new File("");
								JFileChooser wybor = new JFileChooser();
								
								wybor.setCurrentDirectory(new File("./"));
								wybor.setDialogTitle("Select class implementation");
								wybor.setFileFilter(new FileFilter() {
									@Override
									public String getDescription() {
										return null;
									}
								
									@Override
									public boolean accept(File f) {
										if (f.isDirectory()) {
											return true;
										    }
										if (f.getName().substring(f.getName().indexOf(".")+1).equals("class"))
											return true;
										else
											return false;
									}
								
								});
								int wynik = wybor.showOpenDialog(wybor);
								if (wynik == JFileChooser.CANCEL_OPTION)
									return;
								try {
									plik = wybor.getSelectedFile();
									} catch (Exception e) {
									System.out
										.println("Adonath: Error reading file");
								}
									
									System.out.println("ext: " + lastUsed.Name());
								//TODO add your code for jLabel17.mouseClicked
							}
						});
					
					}
					{
						jLabel18 = new JLabel();
						jPanelOPS.add(jLabel18);
						jLabel18.setText("it3");
						jLabel18.setIcon(new ImageIcon("pic\\build.png"));
						jLabel18.setToolTipText("Build system configuration");
						jLabel18.setBounds(0, 71, 32, 28);
						jLabel18.addMouseListener(new MouseAdapter() {
							public void mouseReleased(MouseEvent evt) {
								jLabel18.setBorder(null);
							}
							public void mousePressed(MouseEvent evt) {
								//								jLabel17.setBorder(new EtchedBorder(new Color(
										//									0,
										//									0,
										//									255), new Color(120, 120, 222)));
								jLabel18.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
							}
							public void mouseClicked(MouseEvent evt) {
								File plik=new File("");
								JFileChooser wybor = new JFileChooser();
								
								wybor.setCurrentDirectory(new File("./"));
								wybor.setDialogTitle("Select class implementation");
								wybor.setFileFilter(new FileFilter() {
									@Override
									public String getDescription() {
										return null;
									}
									
									@Override
									public boolean accept(File f) {
										if (f.isDirectory()) {
											return true;
										}
										if (f.getName().substring(f.getName().indexOf(".")+1).equals("class"))
											return true;
										else
											return false;
									}
									
								});
								int wynik = wybor.showOpenDialog(wybor);
								if (wynik == JFileChooser.CANCEL_OPTION)
									return;
								try {
									plik = wybor.getSelectedFile();
								} catch (Exception e) {
									System.out
									.println("Adonath: Error reading file");
								}
								
								System.out.println("ext: " + lastUsed.Name());
								//TODO add your code for jLabel17.mouseClicked
							}
						});
					}
					{
						jLabel19 = new JLabel();
						jPanelOPS.add(jLabel19);
						jLabel19.setText("it4");
						jLabel19.setIcon(new ImageIcon("pic\\add.png"));
						jLabel19.setToolTipText("Add to system configuration");
						jLabel19.setBounds(0, 105, 32, 27);
						jLabel19.addMouseListener(new MouseAdapter() {
							public void mouseReleased(MouseEvent evt) {
								jLabel18.setBorder(null);
							}
							public void mousePressed(MouseEvent evt) {
								//								jLabel17.setBorder(new EtchedBorder(new Color(
										//									0,
										//									0,
										//									255), new Color(120, 120, 222)));
								jLabel18.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
							}
							public void mouseClicked(MouseEvent evt) {
								File plik=new File("");
								JFileChooser wybor = new JFileChooser();
								
								wybor.setCurrentDirectory(new File("./"));
								wybor.setDialogTitle("Select class implementation");
								wybor.setFileFilter(new FileFilter() {
									@Override
									public String getDescription() {
										return null;
									}
									
									@Override
									public boolean accept(File f) {
										if (f.isDirectory()) {
											return true;
										}
										if (f.getName().substring(f.getName().indexOf(".")+1).equals("class"))
											return true;
										else
											return false;
									}
									
								});
								int wynik = wybor.showOpenDialog(wybor);
								if (wynik == JFileChooser.CANCEL_OPTION)
									return;
								try {
									plik = wybor.getSelectedFile();
								} catch (Exception e) {
									System.out
									.println("Adonath: Error reading file");
								}
								
								System.out.println("ext: " + lastUsed.Name());
								//TODO add your code for jLabel17.mouseClicked
							}
						});
					}
					{
						jLabel20 = new JLabel();
						jPanelOPS.add(jLabel20);
						jLabel20.setText("it5");
						jLabel20.setIcon(new ImageIcon("pic\\remove.png"));
						jLabel20.setToolTipText("Remove from system configuration");
						jLabel20.setBounds(0, 135, 32, 28);
						jLabel20.addMouseListener(new MouseAdapter() {
							public void mouseReleased(MouseEvent evt) {
								jLabel20.setBorder(null);
							}
							public void mousePressed(MouseEvent evt) {
								//								jLabel17.setBorder(new EtchedBorder(new Color(
										//									0,
										//									0,
										//									255), new Color(120, 120, 222)));
								jLabel20.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
							}
							public void mouseClicked(MouseEvent evt) {
								File plik=new File("");
								JFileChooser wybor = new JFileChooser();
								
								wybor.setCurrentDirectory(new File("./"));
								wybor.setDialogTitle("Select class implementation");
								wybor.setFileFilter(new FileFilter() {
									@Override
									public String getDescription() {
										return null;
									}
									
									@Override
									public boolean accept(File f) {
										if (f.isDirectory()) {
											return true;
										}
										if (f.getName().substring(f.getName().indexOf(".")+1).equals("class"))
											return true;
										else
											return false;
									}
									
								});
								int wynik = wybor.showOpenDialog(wybor);
								if (wynik == JFileChooser.CANCEL_OPTION)
									return;
								try {
									plik = wybor.getSelectedFile();
								} catch (Exception e) {
									System.out
									.println("Adonath: Error reading file");
								}
								
								System.out.println("ext: " + lastUsed.Name());
								//TODO add your code for jLabel17.mouseClicked
							}
						});
					}
				}
			}

			{
				jPopup=new JPopupMenu();
				final JMenuItem mnu=new JMenuItem("Copy");
				final JMenuItem mnu1=new JMenuItem("Cut");
				final JMenuItem mnu2=new JMenuItem("Paste as Child");
				jPopup.add(mnu);
				jPopup.add(mnu1);
				jPopup.add(mnu2);
				mnu2.setVisible(false);
				
				ActionListener menuAL=new ActionListener(){
				    public void actionPerformed(ActionEvent e) {
				    	JMenuItem source = (JMenuItem)(e.getSource());
				    	
				    	if(lastSelectedTreeNodePath!=null) lastSelectedTreeNode=(DefaultMutableTreeNode)lastSelectedTreeNodePath.getLastPathComponent();
				    	
				    	if(source==mnu && lastSelectedTreeNode!=null)
				    	{
				    		coppiedTreePart=lastSelectedTreeNode;
				    	}
				    	
				    	if(source==mnu1 && lastSelectedTreeNode!=null)
				    	{
				    		DefaultTreeModel mdl=(DefaultTreeModel)lastSelectedTree.getModel();
				    		coppiedTreePart=lastSelectedTreeNode;
				    		mdl.removeNodeFromParent(lastSelectedTreeNode);
				    	}
				    	
				    	if(source==mnu2 && coppiedTreePart!=null)
				    	{
				    		DefaultMutableTreeNode newPart=CloneTreeNode(coppiedTreePart);
				    		DefaultMutableTreeNode tmpParent=(DefaultMutableTreeNode)lastSelectedTreeNodePath.getLastPathComponent();
				    		DefaultTreeModel mdl=(DefaultTreeModel)lastSelectedTree.getModel();
				    		mdl.insertNodeInto(newPart, tmpParent, tmpParent.getChildCount());
				    		coppiedTreePart=null;
				    	}
				    	
				    	if(coppiedTreePart!=null) mnu2.setVisible(true);
			    		else mnu2.setVisible(false);
				    }};
				
				mnu.addActionListener(menuAL);
				mnu1.addActionListener(menuAL);
				mnu2.addActionListener(menuAL);
			}
			{
				jMenuBar1 = new JMenuBar();
				ButtonGroup jButtonGroup2 = new ButtonGroup();
				setJMenuBar(jMenuBar1);
				jMenuBar1.setPreferredSize(new java.awt.Dimension(480, 24));
				{
					Menu1 = new JMenu();
					jMenuBar1.add(Menu1);
					Menu1.setFont(new Font("Tahoma",12,12));
					Menu1.setText("Manage");
					{
						jMenuItem8 = new JMenuItem();
						Menu1.add(jMenuItem8);
						jMenuItem8.setText("Component File");
						jMenuItem8.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {

								File plik;
								JFileChooser wybor = new JFileChooser();
								DefaultMutableTreeNode st0 = new DefaultMutableTreeNode("Searching");
								final JTree tmptree = new JTree(st0);
								
								tmptree.getSelectionModel().setSelectionMode(
									TreeSelectionModel.SINGLE_TREE_SELECTION);
								tmptree.setPreferredSize(new java.awt.Dimension(180,590));
								vTrees.add(tmptree);

								wybor.setCurrentDirectory(new File("./"));
								int wynik = wybor.showOpenDialog(wybor);
								if (wynik == JFileChooser.CANCEL_OPTION)
									return;
								try {
									plik = wybor.getSelectedFile();
									//Reset();
									stad = new InputTaker(plik.getAbsolutePath());
									
									BuildTree(tmptree);
									AddHist(plik.getAbsolutePath());
									JScrollPane tmp = new JScrollPane();
									tmp.setBounds(35, 21, 185, 390);
									tmp.setViewportView(tmptree);
									jTabbed.addTab(plik.getName(), tmp);

								} catch (Exception e) {
									System.out
										.println("Adonath: Error reading file");
								}

								tmptree
									.addTreeSelectionListener(new TreeSelectionListener() {
										public void valueChanged(
											TreeSelectionEvent evt) {
											try {
												Reset();
												itemSelected(tmptree);
											} catch (NullPointerException e) {
												System.out
													.println("Nothing selected");
											} catch (ClassCastException ce) {
												System.out
													.println("Unknown type selected\n"
														+ ce);
											}
											//TODO o

										}
									});
								tmptree.addMouseListener(new MouseListener() {
									public void mouseClicked(MouseEvent e) {
					                	if (e.isPopupTrigger()) {
					                		lastSelectedTreeNodePath = tmptree.getPathForLocation(e.getX(), e.getY());
					                		lastSelectedTree=tmptree;
					                		if(lastSelectedTreeNodePath!=null)
					                			jPopup.show(e.getComponent(),e.getX(), e.getY());
					                    }
					                }

									public void mouseEntered(MouseEvent e) {
										
									}

									public void mouseExited(MouseEvent e) {
										
									}

									public void mousePressed(MouseEvent e) {
										
									}

									public void mouseReleased(MouseEvent e) { //windows
					                	if (e.isPopupTrigger()) {
					                		lastSelectedTreeNodePath = tmptree.getPathForLocation(e.getX(), e.getY());
					                		lastSelectedTree=tmptree;
					                		if(lastSelectedTreeNodePath!=null)
					                			jPopup.show(e.getComponent(),e.getX(), e.getY());
					                    }										
									};});
								}
						});
					}
					{
						jSeparator5 = new JSeparator();
						Menu1.add(jSeparator5);
					}
					{
						jMenu1a = new JMenu();
						Menu1.add(jMenu1a);
						jMenu1a.setText("Access");
						{
							accessModes = new AccessModeManager();
							accessModes.setDirectory("AccessModes/");
							try{ 
								accessModes.loadPlugins();
							} catch(Exception e)
							{
								System.out.println(e.toString());
							}
							jRadioButtonMenuModes=new Vector<JRadioButtonMenuItem>();
							for(int i=0;i<accessModes.getNumModes();i++)
							{
								JRadioButtonMenuItem tmp= new JRadioButtonMenuItem();
								jRadioButtonMenuModes.add(tmp);
								
								final AccessMode currentMode=(AccessMode)accessModes.getModes().get(i);
								final String modeName=currentMode.getModeName();
								
								tmp.setText(modeName);
								jButtonGroup2.add(tmp);
								jMenu1a.add(tmp);
								
								tmp.addActionListener(new ActionListener() {
								public void actionPerformed(ActionEvent evt) {
									selectedAccessMode=currentMode;
									selectedAccessMode.Init();
									jPanel2.setBorder(BorderFactory.createTitledBorder(null,modeName, TitledBorder.LEADING, TitledBorder.TOP));
								}
								});
							}
							if(accessModes.getNumModes()>0)
							{
								selectedAccessMode=accessModes.getModes().get(0);
								selectedAccessMode.Init();
								jRadioButtonMenuModes.get(0).setSelected(true);
								jPanel2.setBorder(BorderFactory.createTitledBorder(null,selectedAccessMode.getModeName(), TitledBorder.LEADING, TitledBorder.TOP));
							}
						}
						{ 
							JSeparator tmp1 = new JSeparator();
							jMenu1a.add(tmp1);
							JMenuItem tmp = new JMenuItem();
							tmp.setText("Configure");
							final javax.swing.JFrame thisFrame=this;
							tmp.addActionListener(new ActionListener() {
								public void actionPerformed(ActionEvent evt) {
									if(selectedAccessMode!=null) selectedAccessMode.configDialog(thisFrame);
								}
								});
							jMenu1a.add(tmp);
							
						}
					}
					{
						jSeparator6 = new JSeparator();
						Menu1.add(jSeparator6);
					}

				}
				{
					jMenuPar = new JMenu();
					jMenuBar1.add(jMenuPar);
					jMenuPar.setText("Parameters");
				}
				{
					jMenuInt = new JMenu();
					jMenuBar1.add(jMenuInt);
					jMenuInt.setText("Interface");
					jMenuInt.setBounds(105, 0, 49, 21);
				}
				{
					jMenuTol = new JMenu();
					jMenuBar1.add(jMenuTol);
					jMenuTol.setText("Tools");
					{
						jMenuItem9 = new JMenuItem();
						jMenuTol.add(jMenuItem9);
						jMenuItem9.setText("Create XML");
						jMenuItem9.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								ExcelToXML toxml = new ExcelToXML();
								File plik = new File(new File("").getAbsolutePath()+"\\"+lastUsed.getLink()+"\\"+lastUsed.Clear(1)+"\\data.xls");
								toxml.generateXML(plik, lastUsed.Clear(1));
							}
						});
					}
				}
			}
			//BuildTree();
			pack();
			this.setSize(883, 725);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void Reset() {
		jLabel10.setVisible(false);
		jTextFieldListN.setVisible(false);
		TableModel tmod = new DefaultTableModel();
		jTable4.setModel(tmod);
		jTextFieldChar.setText("");
		jTextFieldSize.setText("0");
		jComboBox1.setSelectedIndex(0);
		jTable1.setModel(tmod);
		jTable3.setModel(tmod);
		jTableInt.setModel(tmod);
		rowView = null;
		jPanel5.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), " Parameters ", TitledBorder.LEADING, TitledBorder.TOP));
		jPanel6.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), " Interfaces ", TitledBorder.LEADING, TitledBorder.TOP));
		jTextFieldCharInt.setText("");
		jScrollPane5.setRowHeaderView(rowView);
		jScrollPane6.setRowHeaderView(rowView);
		jAdvButton.setEnabled(false);
	}
	
//	public void BuildTree() {
//		//TreeModel temp;
//		DefaultMutableTreeNode buf1= new DefaultMutableTreeNode();
//		boolean flagEnd=false;
//		CII_Tree_Vectors temp= new CII_Tree_Vectors();
//		//stad = new InputTaker();
//		//stad.init();
//		jTextFieldMW.setText(""+stad.getMainWidth());
//		DefaultMutableTreeNode Root = new DefaultMutableTreeNode("Components:");
//
//		Root= new DefaultMutableTreeNode(stad.getRoot());
//		DefaultTreeModel trm = new DefaultTreeModel(Root);
//		try {
//		for (int i=0;i<11;i++) { //TODO stala wartosc !
//			temp = stad.getNextComp();
//			if (temp.get(9).equals("0") && flagEnd==false/*&& !temp.get(0).equals("-1")*/) {
//				jTextPane1.setText(jTextPane1.getText()+
//						"\n"+temp.get(8));
//				if (temp.get(1).equals("null")) {flagEnd=true;break;}
//				//Root.add(new DefaultMutableTreeNode(temp));
//				trm.insertNodeInto(new DefaultMutableTreeNode(temp), Root, Root.getChildCount());
//			}
//			if (!temp.get(9).equals("0") && !temp.get(0).equals("0") && !temp.get(0).equals("-1")) {
//				System.out.println("Child components: "+temp.get(1)+" of parrent "+temp.toInt(9));
//				DefaultMutableTreeNode dft = new DefaultMutableTreeNode();
//				try {
//				System.out.println("Probuje dodac w "+(temp.toInt(9)-1)+" z "+Root.getChildCount());
//				System.out.println("\n +" + Root.getLastChild().getIndex(Root));
//				dft = (DefaultMutableTreeNode)Root.getLastChild();
//				Helpers helper = new Helpers();
//				System.out.println(":"+Root.getFirstChild() );helper.TrackTree(Root);
//				trm.insertNodeInto(new DefaultMutableTreeNode(temp),
//						(DefaultMutableTreeNode)Root.getChildAt(temp.toInt(9)-1), 
//						Root.getLastLeaf().getChildCount());
//				//dft.add(new DefaultMutableTreeNode(temp));//insert(new DefaultMutableTreeNode(temp.get(1)), in.intValue());
//				//Root.add(dft);
//				buf1=(DefaultMutableTreeNode)dft.getLastChild();
//				
//				} catch (Exception z) {
//					System.out.println("---err\n"+z+"\n-----\n");
//					System.out.println("adding at: "+ (temp.toInt(9)-1));
//					buf1.add(new DefaultMutableTreeNode(temp));
//					System.out.println(" siblings "+Root.getSiblingCount());
//				}
//				
//			}
//		
//		}
//		//tmpRoot.
//		theComponents = stad.tabl.get(0);
//		jTree1.setModel(trm);
//		} catch (Exception x) {
//			System.out.println("Error processing the tree:\n"+x);
//		}
//		//ListModel list = new DefaultComboBoxModel(stad.getCompTokens(0));
//		DefaultListModel listm = new DefaultListModel();
//		Vector ale = new Vector();
//		ale = stad.getCompTokens(0);
//		for (int y=0;y<ale.size();y++) listm.addElement(ale.get(y));
//		
//
//	}
	public DefaultMutableTreeNode CloneTreeNode(DefaultMutableTreeNode node)
	{
		DefaultMutableTreeNode clonedNode=(DefaultMutableTreeNode)node.clone();
		
		Enumeration chldrn=node.children();
		while(chldrn.hasMoreElements())
		{
			DefaultMutableTreeNode chld=(DefaultMutableTreeNode)chldrn.nextElement();
			DefaultMutableTreeNode chldClone;
			if(chld.children().hasMoreElements()) chldClone=CloneTreeNode(chld);
			else chldClone=(DefaultMutableTreeNode)chld.clone();
			clonedNode.add(chldClone);
		}
		return clonedNode;
	}
	
	public void BuildTree(JTree tree) {
		
		int tem=0;
		DefaultMutableTreeNode buf1= new DefaultMutableTreeNode();
		boolean flagEnd=false;
		CII_Tree_Vectors temp;
		//stad = new InputTaker();
		//stad.init();
		jTextFieldMW.setText(""+stad.getMainWidth());
		DefaultMutableTreeNode Root = new DefaultMutableTreeNode("Components:");

		Root= new DefaultMutableTreeNode(stad.getRoot());
		DefaultTreeModel trm = new DefaultTreeModel(Root);
		try {
		for (int i=0;i<15;i++) { //TODO zmienic stala wartosc !
			temp = stad.getNextComp();
			inputTakers.put(temp, stad);
			if (temp.get(9).equals("0") && flagEnd==false/*&& !temp.get(0).equals("-1")*/) {
//				jTextPane1.setText(jTextPane1.getText()+
//						"\n"+temp.get(8));  //INFO wylaczone
				if (temp.get(1).equals("null")) {flagEnd=true;break;}
				//Root.add(new DefaultMutableTreeNode(temp));
				trm.insertNodeInto(new DefaultMutableTreeNode(temp), Root, Root.getChildCount());
			}
			if (!temp.get(9).equals("0") && !temp.get(0).equals("0") && !temp.get(0).equals("-1")) {
				tem++;
				System.out.println("Child components: "+temp.get(1)+" of parrent "+temp.toInt(9));
				DefaultMutableTreeNode dft = new DefaultMutableTreeNode();
				try {
				System.out.println("Probuje dodac w "+(temp.toInt(9)-tem)+" z "+Root.getChildCount());
				System.out.println("\n +" + Root.getLastChild().getIndex(Root));
				dft = (DefaultMutableTreeNode)Root.getLastChild();
				Helpers helper = new Helpers();
				System.out.println(":"+Root.getFirstChild() );helper.TrackTree(Root);
				trm.insertNodeInto(new DefaultMutableTreeNode(temp),
						(DefaultMutableTreeNode)Root.getChildAt(temp.toInt(9)-tem+Root.getLastChild().getChildCount()), 
						Root.getLastChild().getChildCount());
				//dft.add(new DefaultMutableTreeNode(temp));//insert(new DefaultMutableTreeNode(temp.get(1)), in.intValue());
				//Root.add(dft);
				buf1=(DefaultMutableTreeNode)dft.getLastChild();
				
				
				} catch (Exception z) {
					System.out.println("---err\n"+z+"\n-----\n");
					System.out.println("adding at: "+ (temp.toInt(9)-1));
					buf1.add(new DefaultMutableTreeNode(temp));
					System.out.println(" siblings "+Root.getSiblingCount());
				}
			}
		}
		//tmpRoot.
		theComponents = stad.tabl.get(0);
		tree.setModel(trm);
		} catch (Exception x) {
			System.out.println("Error processing the tree:\n"+x);
		}	

	}
	
	private void itemSelected(JTree tree) {
		
		DefaultMutableTreeNode tryn = (DefaultMutableTreeNode)tree.getSelectionPath().getLastPathComponent();
		CII_Tree_Vectors atryn = (CII_Tree_Vectors)tryn.getUserObject();
		lastUsed = atryn;
		stad=inputTakers.get(lastUsed);
		lastUsed.setLink(stad.tabl.get(0).Clear(1).substring(1)+"\\"+atryn.Name());
		System.out.println("lastused : " + lastUsed.Clear(1));
		//ListModel list = new DefaultListModel();
		TableModel tmod = new DefaultTableModel();
		TableModel tmod2 = new DefaultTableModel();
		int compID = new Integer(atryn.get(0));
		if (compID==-1) {
			//list = new DefaultListModel();
			tmod = new DefaultTableModel();
			tmod2 = new DefaultTableModel();
			jTable1.setModel(tmod);
			jTable3.setModel(tmod2);
			rowView = null;
			jScrollPane5.setRowHeaderView(rowView);
		} else {
		rowView = new Rule(Rule.VERTICAL, false);
		//list = new DefaultComboBoxModel(stad.getCompTokens(compID));
		Vector<String> tmp = new Vector<String>();
		//Vector<String> tmp2 = new Vector<String>();
		tmp.add("Name");
		tmp.add("Value");
		
		tmod = new DefaultTableModel(tmp,ParamsCountIntCount(stad.getCompTokens(compID))[0]);
		tmod2 = new DefaultTableModel(tmp,ParamsCountIntCount(stad.getCompTokens(compID))[1]);
		int it1=0, it2=0;
		for (int u=0;u<stad.getCompTokens(compID).size();u++) {
//			System.out.println(u +" "+ stad.getCompTokens(compID).get(u));
//			tmp2.add(new String[] {stad.getCompTokens(compID).get(u).get(1)
//			,stad.getCompTokens(compID).get(u).get(3)
//			,stad.getCompTokens(compID).get(u).get(4)
//			,stad.getCompTokens(compID).get(u).get(5)});
			if (!stad.getCompTokens(compID).get(u).get(2).substring(18).equals("AREA")
				&& !stad.getCompTokens(compID).get(u).get(2).substring(18).equals("WORD")
				&& !stad.getCompTokens(compID).get(u).get(2).substring(18).equals("BITS")
				) {
			tmod.setValueAt(stad.getCompTokens(compID).get(u).get(1).substring(1, 
					stad.getCompTokens(compID).get(u).get(1).length()-1), it1, 0);
			
			tmod.setValueAt(getValue(stad.getCompTokens(compID).get(u)), it1, 1);
			it1++;
//			tmod.setValueAt(stad.getCompTokens(compID).get(u).get(4), u, 2);
//			tmod.setValueAt(stad.getCompTokens(compID).get(u).get(5), u, 3);
				} else {
					tmod2.setValueAt(stad.getCompTokens(compID).get(u).get(1).substring(1, 
							stad.getCompTokens(compID).get(u).get(1).length()-1), it2, 0);
					tmod2.setValueAt(getValue(stad.getCompTokens(compID).get(u)), it2, 1);
					it2++;
				}
			}
		//tmod = new DefaultTableModel(tmp2,tmp);
		
		JTable jTable2 = new JTable();
		jTable3.setModel(tmod2);
		jTable2.setModel(tmod);
		jTable1.setAutoResizeMode(0);
		jTable3.setAutoResizeMode(0);
		//jTable1.setSize(new Dimension(700,500));
		TableColumnModel tcm1 = new DefaultTableColumnModel();
		tcm1 = jTable2.getColumnModel();
		tcm1.getColumn(1).setWidth(20);
		jTable1.setModel(tmod);
		jTable1.setColumnModel(tcm1);
		jTable1.getColumn(jTable1.getColumnName(0)).setMinWidth(jScrollPane2.getWidth()/2);
		jTable1.getColumn(jTable1.getColumnName(1)).setMinWidth(jScrollPane2.getWidth()/2);
		jTable3.getColumn(jTable3.getColumnName(0)).setMinWidth(jScrollPane4.getWidth()/2);
		jTable3.getColumn(jTable3.getColumnName(1)).setMinWidth(jScrollPane4.getWidth()/2);
		//jTable1.setModel(tmod);
		ActOnInt(1);
		}
		jTextFieldCompName.setText(atryn.get(1));
		jTextFieldInd.setText(atryn.get(8));
	}
	
	/**
	 * Function determining access interface's field mode 
	 * @param val determines access mode, if<br><li>0 : cant do anything
	 * <li>1 : Read
	 * <li>2 : Write
	 * <li>3 : Read and Write</li>
	 */
	public void ActOnInt(int val) {
		if (val==0) { canRead=false;
					jMenuItem2.setEnabled(false);
					jMenuItem3.setEnabled(false);
					jMenuItem5.setEnabled(false);
					jMenuItem6.setEnabled(false);
					}
		if (val==1) { canRead=true;
					jMenuItem2.setEnabled(true);
					jMenuItem3.setEnabled(true);
					jMenuItem5.setEnabled(false);
					jMenuItem6.setEnabled(false);
					}
		if (val==2) { canRead=false;
					jMenuItem2.setEnabled(false);
					jMenuItem3.setEnabled(false);
					jMenuItem5.setEnabled(true);
					jMenuItem6.setEnabled(true);					
					}
		if (val==3) { canRead=true;canWrite=true;
					jMenuItem2.setEnabled(true);
					jMenuItem3.setEnabled(true);
					jMenuItem5.setEnabled(true);
					jMenuItem6.setEnabled(true);
					}
	}
	
	/**
	 * 
	 * @param arg
	 * @return an array describies: <br>
	 * value at [0] - number of parameters of this entity<br>
	 * value at [1] - number of interfaces of this entity 
	 */
	public int[] ParamsCountIntCount(Vector<CII_Tree_Vectors> arg) {
		int[] tmp = new int[2];
		for (int u=0;u<arg.size();u++) {
			if (!arg.get(u).get(2).substring(18).equals("AREA")
				&& !arg.get(u).get(2).substring(18).equals("WORD")
				&& !arg.get(u).get(2).substring(18).equals("BITS")
				) {
					tmp[0]++;
				} else {
					
					tmp[1]++;
				}
			}
		return tmp;
	}
	/**
	 * Represents acces mode of parameter <code>atryn</code>
	 * @param atryn
	 */
	public void ShowAccesMode(CII_Tree_Vectors atryn) {
		if (atryn.get(6).equals("CIIlib.TABLE_ACCESS.NA")) {
			jNA.setSelected(true);
			jWrite.setEnabled(false);
			jManag.setEnabled(false);
			jRead.setEnabled(false);
			canRead= false;
			canWrite = false;
		}
		if (atryn.get(6).equals("CIIlib.TABLE_ACCESS.RO")) {
			jRO.setSelected(true);
			jWrite.setEnabled(false);
			jManag.setEnabled(false);
			jRead.setEnabled(true);
			canRead= true;
			canWrite = false;
		}
		if (atryn.get(6).equals("CIIlib.TABLE_ACCESS.IR")) {
			jIR.setSelected(true);
			jWrite.setEnabled(true);
			jManag.setEnabled(true);
			jRead.setEnabled(true);
			canRead= true;
			canWrite = true;
		}
		if (atryn.get(6).equals("CIIlib.TABLE_ACCESS.RC")) {
			jRC.setSelected(true);
			jWrite.setEnabled(false);
			jManag.setEnabled(false);
			jRead.setEnabled(true);
			canRead= true;
			canWrite = false;
		}
		if (atryn.get(6).equals("CIIlib.TABLE_ACCESS.WO")) {
			jWO.setSelected(true);
			jWrite.setEnabled(true);
			jManag.setEnabled(false);
			jRead.setEnabled(false);
			canRead= false;
			canWrite = true;
		}
		if (atryn.get(6).equals("CIIlib.TABLE_ACCESS.RW")) {
			jRW.setSelected(true);
			jWrite.setEnabled(true);
			jManag.setEnabled(true);
			jRead.setEnabled(true);
			canRead= true;
			canWrite = true;
		}
	}
	/**
	 * Represents data...
	 * @param atryn
	 */
	public void EngageData(CII_Tree_Vectors atryn) {
		jLabel10.setVisible(false);
		jTextFieldListN.setVisible(false);
		ShowAccesMode(atryn);
		int data4 = new Integer(atryn.get(4));
		int data5 = new Integer(atryn.get(5));
		//when is a scalar !
		jTextFieldSize.setText(atryn.get(3).equals("0")?"1":atryn.get(3));
		if (data4 == 1 && data5== 1) {
			//is a string
			if (atryn.isString()) {
				jTextFieldChar.setText("String");
				jComboBox1.setSelectedIndex(0);
				DisplayScalar(jTable4, atryn.Clear(10));
			}
			if (atryn.isInteger()) {
				jTextFieldChar.setText("Integer");
				jComboBox1.setSelectedIndex(1);
				DisplayScalar(jTable4, atryn.get(9));
			}
			if (atryn.isHex()) {
				jTextFieldChar.setText("Hexadecimal");
				jComboBox1.setSelectedIndex(3);
				DisplayScalar(jTable4, atryn.Clear(10));
			}
			if (atryn.isList()) {
				jTextFieldChar.setText("List element");
				jLabel10.setVisible(true);
				jTextFieldListN.setVisible(true);
				jTextFieldListN.setText(atryn.get(10));
				jComboBox1.setSelectedIndex(1);
				DisplayScalar(jTable4,atryn.get(9));
			}
			if (atryn.isLogic()) {
				jTextFieldChar.setText("Logic");
				jComboBox1.setSelectedIndex(0);
				DisplayScalar(jTable4, getValue(atryn));
				
			}
			
		}
		//when is a matrix !
		else {
			if (atryn.isString()) {
				jTextFieldChar.setText("String");
				jComboBox1.setSelectedIndex(0);
				DisplayMatrix(jTable4,atryn);
			}
			if (atryn.isInteger()) {
				jTextFieldChar.setText("Integer");
				jComboBox1.setSelectedIndex(1);
				DisplayMatrix(jTable4,atryn);
			}
			if (atryn.isHex()) {
				jTextFieldChar.setText("Hexadecimal");
				jComboBox1.setSelectedIndex(3);
				DisplayMatrix(jTable4,atryn);
			}
			if (atryn.isList()) {
				jTextFieldChar.setText("List element");
				jLabel10.setVisible(true);
				jTextFieldListN.setVisible(true);
				jTextFieldListN.setText(atryn.get(10));
				jComboBox1.setSelectedIndex(1);
				DisplayMatrix(jTable4,atryn);
			}
		}
		
	
	}
	
	public void EngageData2(CII_Tree_Vectors atryn) {
		lastInterface=atryn;
		ShowAccesMode(atryn);
		if (atryn.isNomore()) {
			jTextFieldCharInt.setText("Null");
			jTableInt.setModel(new DefaultTableModel());
			rowView = null;
			jScrollPane6.setRowHeaderView(rowView);
			rowView = new Rule(Rule.VERTICAL, false);
			return;
		}
		if (atryn.isBits()) {
			jTextFieldCharInt.setText("Bits");
			DisplayInterface(jTableInt,atryn);
		}
		if (atryn.isWord()) {
			jTextFieldCharInt.setText("Word");
			DisplayInterface(jTableInt,atryn);
		}
		if (atryn.isArea()) {
			jTextFieldCharInt.setText("Area");
			DisplayInterface(jTableInt,atryn);
		}
		
	}
	/**
	 * Displays 1x1 table
	 * @param where
	 * @param val
	 */
	public void DisplayScalar(Component where, Object val) {
		
		if (where instanceof JTable) {
			JTable tym = new JTable();
			Vector tmp = new Vector();
			tmp.add("Value");
			TableModel tmod = new DefaultTableModel();
			tmod = new DefaultTableModel(tmp,1);
			tmod.setValueAt(val, 0, 0);
			tym = (JTable)where;
			tym.setModel(tmod);
			columnView.setPreferredWidth(where.getWidth());
			rowView.Adjust(tym);
		    jScrollPane5.setRowHeaderView(rowView);
		}
		
		
	}
	
	public void DisplayMatrix(Component where, CII_Tree_Vectors valof) {
		
		int x = new Integer(valof.get(4));
		int y = new Integer(valof.get(5));
		if (x>=10) CallToResizeRule(x);
		else rowView.SIZE=16;
		CII_Tree_Vectors tm = new CII_Tree_Vectors();

		DefaultTableModel tmod = new DefaultTableModel();
		
		if (where instanceof JTable) {
			JTable tym = new JTable();
			
			Object[][] data = new Object[x][y];
			
			tm = valof;
			int iter = x*y;
			
			for (int i=0;i<iter-1;i++) {
				int xx = new Integer(stad.getNextLine(tm,new Integer(lastUsed.get(0))).get(7));
				int yy = new Integer(stad.getNextLine(tm,new Integer(lastUsed.get(0))).get(8));
				if (valof.isString() || valof.isHex()) {
					tmod.addRow(new Object[] { "Line: "+i });
					data[0][0] = valof.Clear(10);
					data[xx][yy] = stad.getNextLine(tm,new Integer(lastUsed.get(0))).Clear(10);
				} // <- string
				if (valof.isInteger() || valof.isList()) {
					data[0][0] = valof.get(9);
					data[xx][yy] = stad.getNextLine(tm,new Integer(lastUsed.get(0))).get(9);
				} // <- int
				tm = stad.getNextLine(tm, new Integer(lastUsed.get(0)));
			} // <- for
			
			
			Object[] column = new Object[y];
			for (int k=0;k<y;k++) column[k]=k;
			tmod = new DefaultTableModel(data,column);
			//tmod.setValueAt(val, 0, 0);
			tym = (JTable)where;
			tym.setModel(tmod);
			columnView.setPreferredWidth(where.getWidth());
			rowView.Adjust(tym);
		    jScrollPane5.setRowHeaderView(rowView);
		}
	}
	
public void DisplayInterface(Component where, CII_Tree_Vectors valof) {
		int x = new Integer(valof.get(4));
		int y = new Integer(valof.get(5));

		XmlInterfaceData ifdata;
		
		if(!(ifDatas.containsKey(valof)))
		{
			ifdata=new XmlInterfaceData();
			ifdata.setInterface(valof);
			ifDatas.put(valof,ifdata);
		} else ifdata=ifDatas.get(valof);
				
	
		File file = new File("./Cache/"+lastUsed.getLink()+"/"+lastUsed.Clear(1)+"/data.xml");

		if(file.exists())
		{
			try {
			ifdata.importXML(new FileInputStream(file));
			} catch (Exception e) {
				file.delete();
				e.printStackTrace();
			}
		}
		
		if (x>=10) CallToResizeRule(x);
		else Rule.SIZE=16;

		JTable tym = (JTable)where;
		tym.setModel(ifdata);
		columnView.setPreferredWidth(where.getWidth());
		rowView.Adjust(tym);
	    jScrollPane6.setRowHeaderView(rowView);
}

public void DisplayEditTest(Component where) {
		
	CII_table_mod_render tmodren = new CII_table_mod_render();
	CII_test_cellRend er = new CII_test_cellRend();
	CII_tableRender trr = new CII_tableRender();
	
		int x = lastUsed.toInt(4);//new Integer(valof.get(4));
		int y = lastUsed.toInt(5);//new Integer(valof.get(5));
		if (x>=10) CallToResizeRule(x);
		else rowView.SIZE=16;
		DefaultTableModel tmod = new DefaultTableModel();
		
		if (where instanceof JTable) {
			JTable tym = new JTable();
			
			Object[][] data = new Object[x][2*y];
			
			int iter = x*y;
			
			File plik = new File(new File("").getAbsolutePath()+"\\"+lastUsed.getLink()+"\\"+lastUsed.Clear(1)+"\\data.xls");
			if (plik.exists()) { 
				for (int o=0;o<2*y;o++) {
					for(int ox=0;ox<x;ox++) {
						System.out.println(":"+ox+" "+o);
						data[ox][o] = toxls.getData(ox, o/2, plik);
					}
					o++;
				}
			} else {
				for (int o=0;o<y;o++) {
					for(int ox=0;ox<x;ox++) {
						data[ox][o] = " ";
					}
					o++;
				}
			}
			
			Object[] column = new Object[2*y];
			for (int k=0;k<2*y;k++) {
				column[k]="["+k/2+"] read";
				column[k+1]="["+k/2+"] write";
				k++;
			}
			tmod = new DefaultTableModel(data,column);
			tym.setDefaultRenderer(Component.class,
					new TFCCRender(tym.getDefaultRenderer(Component.class)));
			tym = (JTable)where;
			
//			tym.setModel(er);
			TableColumnModel ttcm = tym.getColumnModel();
			 for (int c = 0; c < tym.getColumnCount(); c++)
			   {
				 
			      TableColumn tc = ttcm.getColumn (c);
			      tc.setCellRenderer (trr);
			   }
			
			tym.repaint();
			TableColumn tc = new TableColumn(0), tc2 = new TableColumn(1);
			tc.setHeaderValue("1");
			//tc = jTable3.getColumn(jTable3.getColumnName(0));
			//tc2 = jTable3.getColumn(jTable3.getColumnName(1));
			tc2.setHeaderValue("2");
			jTableInt.setModel(tmod);
			jTableInt.setEditingColumn(0);
			//jTableInt.addColumn(tc);
			//jTableInt.addColumn(tc2);
			columnView.setPreferredWidth(where.getWidth());
			rowView.Adjust(tym);
			
		    jScrollPane6.setRowHeaderView(rowView);
		}
		
	}	
	public void CallToResizeRule(int x) {
		int ilC= 1,tmp;
//		Math.pow(a, b)
		while (true){
			tmp=x/((int)Math.pow(10, ilC));
			if (tmp==0) break;
			ilC++;
		}
		rowView.SIZE = 12*ilC;
	}
	
	public String getValue(CII_Tree_Vectors arg) {
		CII_Tree_Vectors tm = new CII_Tree_Vectors();
		String ret = new String(" ");
		if (arg.get(2).substring(18).equals("SPAR")) {
			if (arg.get(4).equals("1") && arg.get(5).equals("1")) ret = arg.get(10);
			else {
				tm = arg;
				ret = arg.get(10)+"|";
				int iter = (new Integer(arg.get(4)))*(new Integer(arg.get(5)));
				for (int i=0;i<iter-1;i++) {
					ret = ret+ stad.getNextLine(tm,new Integer(lastUsed.get(0))).get(10)+"|";
					tm = stad.getNextLine(tm, new Integer(lastUsed.get(0)));
				}
			}
		} 
		if (arg.get(2).substring(18).equals("IPAR")) {
			if (arg.get(4).equals("1") && arg.get(5).equals("1")) ret = arg.get(9);
			else {
				tm = arg;
				ret = arg.get(9)+"|";
				int iter = (new Integer(arg.get(4)))*(new Integer(arg.get(5)));
				for (int i=0;i<iter-1;i++) {
				
					ret = ret+ stad.getNextLine(tm,new Integer(lastUsed.get(0))).get(9)+"|";
					tm = stad.getNextLine(tm, new Integer(lastUsed.get(0)));
				}
			}
		}
		if (arg.get(2).substring(18).equals("LPAR")) {
			if (arg.get(9).equals("0")) return "false";
			if (arg.get(9).equals("1")) return "true";
		}
		if (arg.get(2).substring(18).equals("HPAR")) {
			ret = "0x"+arg.get(10).substring(1, arg.get(10).length()-1);
		}
		if (arg.get(2).substring(18).equals("VPAR")) {
			ret = arg.get(10).substring(1, arg.get(10).length()-1);
		}
		if (arg.get(2).substring(18).equals("MPAR")) {
			ret = arg.get(10);
		}
		if (arg.isList()) {
			ret = arg.get(9)+" ("+arg.Clear(10)+")";
		}
		
		return ret;
	}
	public int FindTreeRoot( ) {
		return 0;
	}
	
	/**
	 * Reading one, selected cell.
	 *
	 */
	public long Read_one() {
		if(this.selectedAccessMode==null) return -9;
		
		CIIdata Word=new CIIdata(lastUsed.toInt(3));
	    CIIdata Area=new CIIdata(lastUsed.toInt(3));
	    CIIdata Bits=new CIIdata(lastUsed.toInt(3));
	    CIIdata a=new CIIdata(lastUsed.toInt(3));
	    
		try {
			selectedAccessMode.Connect();
			if (lastUsed.isWord()) {
				System.out.println("is word");
				a=selectedAccessMode.readWord(stad.getMainWidth(), 
						Word.GetWidth(),lastUsed.toInt(4), 
											lastUsed.toInt(5), 
											lastUsed.toInt(7),
											int_lastCellSell[1], 
											int_lastCellSell[0], 
											Word);
			if (jComboBox2.getSelectedIndex()==0) {
				jTableInt.setValueAt(Word.GetBin(), int_lastCellSell[1], int_lastCellSell[0]);
			} 
			if (jComboBox2.getSelectedIndex()==1) {
				jTableInt.setValueAt(Word.GetHex(),  int_lastCellSell[1], int_lastCellSell[0]);
			}
			if (jComboBox2.getSelectedIndex()==2) {
				jTableInt.setValueAt(Word.GetValue(),  int_lastCellSell[1], int_lastCellSell[0]);
			}
			if (jComboBox2.getSelectedIndex()==3) {
				jTableInt.setValueAt(Word.GetStr(),  int_lastCellSell[1], int_lastCellSell[0]);
			}
			
			
			}
			if (lastUsed.isArea()) {
				System.out.println("is adrea");
				a=selectedAccessMode.readArea(stad.getMainWidth(), 
						Area.GetWidth(),lastUsed.toInt(4), 
											lastUsed.toInt(5), 
											lastUsed.toInt(7),
											int_lastCellSell[1], 
											int_lastCellSell[0], 
											Area); 
				if (jComboBox2.getSelectedIndex()==0) {
					jTableInt.setValueAt(Area.GetBin(), int_lastCellSell[1], int_lastCellSell[0]);
				} 
				if (jComboBox2.getSelectedIndex()==1) {
					jTableInt.setValueAt(Area.GetHex(),  int_lastCellSell[1], int_lastCellSell[0]);
				}
				if (jComboBox2.getSelectedIndex()==2) {
					jTableInt.setValueAt(Area.GetValue(),  int_lastCellSell[1], int_lastCellSell[0]);
				}
				if (jComboBox2.getSelectedIndex()==3) {
					jTableInt.setValueAt(Area.GetStr(),  int_lastCellSell[1], int_lastCellSell[0]);
				}
				
			}
			if (lastUsed.isBits()) {
				a=selectedAccessMode.readBit(stad.getMainWidth(), 
						Bits.GetWidth(),lastUsed.toInt(4), 
											lastUsed.toInt(5), 
											lastUsed.toInt(7),
											int_lastCellSell[1], 
											int_lastCellSell[0],
											lastUsed.toInt(8),
											Bits);
				if (jComboBox2.getSelectedIndex()==0) {
					jTableInt.setValueAt(Bits.GetBin(), int_lastCellSell[1], int_lastCellSell[0]);
				} 
				if (jComboBox2.getSelectedIndex()==1) {
					jTableInt.setValueAt(Bits.GetHex(),  int_lastCellSell[1], int_lastCellSell[0]);
				}
				if (jComboBox2.getSelectedIndex()==2) {
					jTableInt.setValueAt(Bits.GetValue(),  int_lastCellSell[1], int_lastCellSell[0]);
				}
				if (jComboBox2.getSelectedIndex()==3) {
					jTableInt.setValueAt(Bits.GetStr(),  int_lastCellSell[1], int_lastCellSell[0]);
				}
				
			}
			System.out.println("odczytane "+a.GetStr());
			
			System.out.println("!zaznaczenie :"+stad.getMainWidth()
					+" "+ lastUsed.toInt(3)+" "+  lastUsed.toInt(4)+" "+ lastUsed.toInt(5)+" "+ 
					int_lastCellSell[0]+" "+  int_lastCellSell[1]+" "+  lastUsed.toInt(7)+" "+  lastUsed.toInt(8));
			/*File plik = new File(new File("").getAbsolutePath()+"\\"+lastUsed.getLink()+"\\"+lastUsed.Clear(1)+"\\data.xls");
			if (!plik.exists()) toxls.fileName(lastUsed.getLink()+"\\"+lastUsed.Clear(1));
			if (plik.exists()) toxls.setPath(plik.getAbsolutePath());
		*/
			jTableInt.getModel().setValueAt(new Integer((int)a.GetValue()), int_lastCellSell[1], int_lastCellSell[0]);
			//toxls.addData(int_lastCellSell[1],int_lastCellSell[0],a.GetValue());

			selectedAccessMode.Disconnect();

		} catch (AccessModeException e) {
			System.out.println("Server "+e);
			e.printStackTrace();
			return -1;
		}

		return a.GetValue();
	}
		
	public void Write_one(long data) {
		if(selectedAccessMode==null) return;
		
		CIIdata Word=new CIIdata(lastUsed.toInt(3));
		CIIdata Area=new CIIdata(lastUsed.toInt(3));
		CIIdata Bits=new CIIdata(lastUsed.toInt(3));
		
		Word.SetValue(data);
		Area.SetValue(data);
		Bits.SetValue(data);
		try {
			selectedAccessMode.Connect();
			if (lastUsed.isWord()) {
				selectedAccessMode.writeWord(stad.getMainWidth(), 
										lastUsed.toInt(3), 
										lastUsed.toInt(4), 
										lastUsed.toInt(5), 
										lastUsed.toInt(7),
										int_lastCellSell[1], 
										int_lastCellSell[0]/2, 
										Word);
										System.out.println("zapisane "+data);
			}
			if (lastUsed.isBits()) {
				selectedAccessMode.writeBit(stad.getMainWidth(),
						lastUsed.toInt(3), //szerokosc slowa
						lastUsed.toInt(4), //elem w grp
						lastUsed.toInt(5), //ile grp
						lastUsed.toInt(7), //adres na chipie
						int_lastCellSell[1], 
						int_lastCellSell[0]/2,
						lastUsed.toInt(8), //pozycja na szynie danych
						Bits); // dane
						System.out.println("zapisane "+data);
			}
			if (lastUsed.isArea()) {
				selectedAccessMode.writeArea(stad.getMainWidth(), 
						lastUsed.toInt(3), 
						lastUsed.toInt(4), 
						lastUsed.toInt(5), 
						lastUsed.toInt(7),
						int_lastCellSell[1], 
						int_lastCellSell[0]/2, 
						Area);
						System.out.println("zapisane "+data);
			}
			
			
			System.out.println("!zaznaczenie :"+stad.getMainWidth()
					+" "+ lastUsed.toInt(3)+" "+  lastUsed.toInt(4)+" "+ lastUsed.toInt(5)+" "+ 
					int_lastCellSell[0]+" "+  int_lastCellSell[1]+" "+  lastUsed.toInt(7)+" "+  lastUsed.toInt(8));
			write_fake(data);
			
			selectedAccessMode.Disconnect();
			
	//		if (jComboBox2.getSelectedIndex()==0) {
	//			jTableInt.setValueAt(Long.toBinaryString(a), int_lastCellSell[1], int_lastCellSell[0]);
	//		} 
	//		if (jComboBox2.getSelectedIndex()==1) {
	//			jTableInt.setValueAt(Hex.toString(a),  int_lastCellSell[1], int_lastCellSell[0]);
	//		}
			
			} catch (AccessModeException e) {
				System.out.println("Server "+e);	
			}
	}
	
	public void AddHist(String arg) {
		{
			
			filesHist.add(RegisterOps.currNum,new JMenuItem());
			RegisterOps.getCurrNum();
			Menu1.add(filesHist.get(RegisterOps.currNum));
			filesHist.get(RegisterOps.currNum).setText(arg);
			filesHist.get(RegisterOps.currNum).setVisible(true);
			RegisterOps.addLastOpened(arg);
		}
	}
	
	public void ShowHist() {
		int i=0;
		while (!RegisterOps.getLastOpened(i).equals("Out of range")) {
			System.out.println(RegisterOps.getLastOpened(i)+" " +i);
			i++;
		}
	}
	
	/**
	 * Reading sellection.
	 * 
	 * @param from_to
	 */
	public void Read_many (Insets from_to) {
		int_lastCellSell[0] = from_to.left;
		int_lastCellSell[1] = from_to.top;
			for (int i=from_to.left;i<from_to.right+1;i++) {
				for (int j=from_to.top;j<from_to.bottom+1;j++) {
					int_lastCellSell[0]=i;
					int_lastCellSell[1]=j;
					//Read_one();
					Read_fake();
					System.out.println(int_lastCellSell[0]+" "+int_lastCellSell[1]+" readed");
				}
			}
	}
	
	public void Write_many (Insets from_to) {
		int_lastCellSell[0] = from_to.left;
		int_lastCellSell[1] = from_to.top;
		long tm=0;
			for (int i=from_to.left;i<from_to.right+1;i++) {
				for (int j=from_to.top;j<from_to.bottom+1;j++) {
					int_lastCellSell[0]=i;
					int_lastCellSell[1]=j;
					try {
						tm = new Long(""+jTableInt.getValueAt(j,i));
					} catch (Exception e ) {
						System.out.println("Warning: discovered empty field, no action taken");
						tm = 0; return; }
					Write_one(tm);
					System.out.println(int_lastCellSell[0]+" "+int_lastCellSell[1]+" writen");
				}
			}
	}
	
	private void setComponentPopupMenu(
		final java.awt.Component parent,
		final javax.swing.JPopupMenu menu) {
		parent.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mousePressed(java.awt.event.MouseEvent e) {
				int temp=1;
				if (e.isPopupTrigger())
					menu.show(parent, e.getX(), e.getY());
					if (parent instanceof JTable) {
						JTable table = (JTable) parent;
						temp=table.getColumnCount();
					}
					if ((e.getX()/(parent.getWidth()/temp))%2==0) ActOnInt(1); 
					else ActOnInt(2);
					System.out.println("popup:" + e.getX()/(parent.getWidth()/temp) + " " + (e.getX()/(parent.getWidth()/temp))%2);
			}
			public void mouseReleased(java.awt.event.MouseEvent e) {
				if (e.isPopupTrigger())
					menu.show(parent, e.getX(), e.getY());
			}
		});
	}
	
	public void Read_fake() {
		java.util.Random a = new java.util.Random();
		long readed = (long)(a.nextInt(10)+1);
		CellKeeper ck = new CellKeeper();
		ck.setData(readed);
		jTableInt.setValueAt(ck, int_lastCellSell[1], int_lastCellSell[0]);
		if (jComboBox2.getSelectedIndex()==0) {
			//jTableInt.setValueAt(readed, int_lastCellSell[1], int_lastCellSell[0]);
		} 
		if (jComboBox2.getSelectedIndex()==1) {
			//jTableInt.setValueAt(readed,  int_lastCellSell[1], int_lastCellSell[0]);
		}
		/*
		File plik = new File(new File("").getAbsolutePath()+"\\"+lastUsed.getLink()+"\\"+lastUsed.Clear(1)+"\\data.xls");
		if (!plik.exists()) toxls.fileName(lastUsed.getLink()+"\\"+lastUsed.Clear(1));
		if (plik.exists()) toxls.setPath(plik.getAbsolutePath());*/
		//toxls.addData(int_lastCellSell[1],int_lastCellSell[0],readed);
		jTableInt.setValueAt(new Integer((int)readed),int_lastCellSell[1] ,int_lastCellSell[0]);
	}
	
	public void write_fake(long data) {
		File plik = new File(new File("").getAbsolutePath()+"\\"+lastUsed.getLink()+"\\"+lastUsed.Clear(1)+"\\data.xls");
		if (!plik.exists()) toxls.fileName(lastUsed.getLink()+"\\"+lastUsed.Clear(1));
		if (plik.exists()) toxls.setPath(plik.getAbsolutePath());
		toxls.addData(int_lastCellSell[1],int_lastCellSell[0]/2,data);
	}
	
	private void addAdvancedView()
	{
		final AdvancedView tmp=new AdvancedView();
		vAdvViews.add(tmp);
		AdvancedView.AdvancedInterfaceTablePanel tbl=tmp.addInterface(lastInterface,ifDatas.get(lastInterface));
		tmp.setVisible(true);
		
		tmp.addWindowListener( new WindowAdapter() 
		{ 
			public void windowClosing(WindowEvent e)
			{ 
				Iterator<CII_Tree_Vectors> it=tmp.getInterfaces().iterator();
				while(it.hasNext())
				{
					CII_Tree_Vectors face=it.next();
					AdvancedView.AdvancedInterfaceTablePanel pnl=tmp.getInterfaceTable(face);
					String fname="./Cache/"+face.getLink()+"/"+face.Clear(1)+"/data.xml";
					try {
						File file=new File(fname);
						if(!file.exists())
						{
							try {
								file.getParentFile().mkdirs();
								file.createNewFile();
							} catch (IOException e3) {
								e3.printStackTrace();
							}
						}
						pnl.getInterfaceData().exportXML(new FileOutputStream(file),null);
					} catch (FileNotFoundException e1) {
						e1.printStackTrace();
					}			
				}
				tmp.dispose();
				vAdvViews.remove(tmp);
			} 
		});
		tbl.setAccessMode(selectedAccessMode);
	}
	
	private void updateViewList(JMenu menu)
	{
		menu.removeAll();
		Iterator<AdvancedView> it=vAdvViews.iterator();
		while(it.hasNext())
		{
			final AdvancedView obj=it.next();
			final JMenu finalMenu=menu;
			JMenuItem mnuItm=new JMenuItem(obj.getTitle());
			menu.add(mnuItm);
			System.out.println("dodal: "+obj.getTitle());
			mnuItm.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent arg0) {
					AdvancedView tmp=obj;
					AdvancedView.AdvancedInterfaceTablePanel tbl=tmp.addInterface(lastInterface,ifDatas.get(lastInterface));
					tmp.setVisible(true);
					tbl.setData(ifDatas.get(lastInterface));
					tbl.setAccessMode(selectedAccessMode);
					updateViewList(finalMenu);
				}
			});
		}
	}
	
	private void useModify() {
		if (jButtonWW.getText().equals("Done")) {
			  jButtonWW.setText("Modify");
			  DisplayInterface(jTableInt, lastUsed);
			  //ActOnInt(1);
			  return;
		} if (jButtonWW.getText().equals("Modify")) 
		  {
			  if (canWrite) {
				  //ActOnInt(3);
				  jButtonWW.setText("Done");
				  DisplayEditTest(jTableInt);
			  }
			  else {
				  System.out.println("Cant modify due to access mode");
			  } 
		  } 
	}
	
	public JTree getSystemTree() {
		systemTree.setModel(null);
		XMLTreeView xmlTreeView = new XMLTreeView("system.xml");
		systemTree = new JTree(xmlTreeView.getTreeNode());
		systemTree.addTreeSelectionListener(new TreeSelectionListener() {
			public void valueChanged(TreeSelectionEvent evt) {
				systemTreeValueChanged(evt);
			}
		});
		return systemTree;
	}
	
	private void systemTreeValueChanged(TreeSelectionEvent evt) {
		String data=""+
				systemTree.getLastSelectedPathComponent();
		if (data.contains("cfgPath"))  {
	   String plik=data.trim().split("cfgPath=")[1];
	    try {
			//Reset();
			stad = new InputTaker(plik);
			DefaultMutableTreeNode st0 = new DefaultMutableTreeNode("Searching");
			final JTree tmptree = new JTree(st0);
			
			tmptree.getSelectionModel().setSelectionMode(
				TreeSelectionModel.SINGLE_TREE_SELECTION);
			tmptree.setPreferredSize(new java.awt.Dimension(180,590));
			vTrees.add(tmptree);
			BuildTree(tmptree);
			AddHist(plik);
			JScrollPane tmp = new JScrollPane();
			tmp.setBounds(35, 21, 185, 390);
			tmp.setViewportView(tmptree);
//			for (int i =0;i<=jTabbed.getTabCount();i++) {
//
//				if (jTabbed.getTitleAt(i).compareToIgnoreCase(""+systemTree.getSelectionPath().getParentPath())==0)
//					{jTabbed.setSelectedIndex(i);}
//				else 
					jTabbed.addTab(""+systemTree.getSelectionPath().getParentPath(), tmp);
				
//			}
			tmptree
			.addTreeSelectionListener(new TreeSelectionListener() {
				public void valueChanged(
					TreeSelectionEvent evt) {
					try {
						Reset();
						itemSelected(tmptree);
					} catch (NullPointerException e) {
						System.out
							.println("Nothing selected");
					} catch (ClassCastException ce) {
						System.out
							.println("Unknown type selected\n"
								+ ce);
					}
					//TODO o

				}
			});
		tmptree.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent e) {
            	if (e.isPopupTrigger()) {
            		lastSelectedTreeNodePath = tmptree.getPathForLocation(e.getX(), e.getY());
            		lastSelectedTree=tmptree;
            		if(lastSelectedTreeNodePath!=null)
            			jPopup.show(e.getComponent(),e.getX(), e.getY());
                }
            }

			public void mouseEntered(MouseEvent e) {
				
			}

			public void mouseExited(MouseEvent e) {
				
			}

			public void mousePressed(MouseEvent e) {
				
			}

			public void mouseReleased(MouseEvent e) { //windows
            	if (e.isPopupTrigger()) {
            		lastSelectedTreeNodePath = tmptree.getPathForLocation(e.getX(), e.getY());
            		lastSelectedTree=tmptree;
            		if(lastSelectedTreeNodePath!=null)
            			jPopup.show(e.getComponent(),e.getX(), e.getY());
                }										
			};});

		} catch (Exception e) {
			System.out
				.println("Adonath: Error reading file");
		}
		} else return;
	}
}
